package y24.m2;

public class Test3 {
    static class Solution {
        public int lengthOfLastWord(String s) {
            int fast = 0;
            int count = 0;
            int l = s.length();
            for (int i = 0; i < l; i++) {
                if (s.charAt(i) == ' '){
                    fast = i;
                    i = kongge(i,s,l);
                    if (i-1 != l-1){
                        count = 0;
                    }
                }
                count++;
            }
            return count-1;
        }

         public int kongge(int i,String s,int l){
            while (i < l){
                if (s.charAt(i) != ' '){
                    return i;
                }
                i++;
            }
            return i;
         }
    }

    public static void main(String[] args) {
        System.out.println(new Solution().lengthOfLastWord("Hello World"));
        System.out.println(new Solution().lengthOfLastWord(" Hello"));
        System.out.println(new Solution().lengthOfLastWord("Hello       "));
    }

}
